<?php

namespace App\Guards;

use App\Models\User;
use App\Models\Luo;
use App\Models\Post;


class UserGuard {
    public static function user_can_login(User $u) {
        return $u->status == 1;
    }

    public static function user_can_visit_luo(User $u, Luo $luo) {
        return $u->get_luo() == $luo || $u->score >= $luo->rule->score;
    }

    public static function user_can_visit_post(User $u, Post $post) {
        return  $post->user == $u || (
            $post->status == 1 && UserGuard::user_can_visit_luo($u, $post->luo)
        );
    }

    public static function user_can_add_post(User $u, Luo $luo) {
        return UserGuard::user_can_visit_luo($u, $luo);
    }
}
